<%@ page import="org.apache.commons.lang.StringUtils,com.hz.framework.util.BusinessException"%>
<%@ page import="com.hz.framework.dao.*,com.hz.supermanage.bean.*,com.hz.supermanage.dao.Constants"%>
<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%
	request.setCharacterEncoding("UTF-8");
	String body="";
    try {
        String posId = request.getParameter("posId");
        if (StringUtils.isBlank(posId)) {
             throw new BusinessException("用户必须有一个隶属的岗位");
        }
        CommonDao dao =new CommonDao();
        //增加至用户主表信息当中
        Hzsyspersonnel per = new Hzsyspersonnel();
        String orgid = request.getParameter("orgId");
        per.setOrgid(orgid);//关联机构id
        Hzsysorganization ds = new Hzsysorganization();
        String dpid = request.getParameter("deptId");
        ds.setDepid(dpid);
        per.setDeptid(ds);//关联部门id
        
        Hzsysorganization dss = new Hzsysorganization();
        String psid = request.getParameter("posId");
        String password = request.getParameter("password");
        dss.setDepid(psid);
        per.setPosid(dss);//关联职位id
        per.setUserid(request.getParameter("userid"));//系统当前人
        per.setPersonname(request.getParameter("personname"));//姓名
        per.setLoginid(request.getParameter("loginid"));//登录名
        per.setSex(request.getParameter("sex"));//性别
        per.setBirthday(request.getParameter("birthday").toString());//出生日期
        System.out.println(request.getParameter("birthday").toString()+"@@@@@");
        per.setWorkday(request.getParameter("workday"));//入职日期
        per.setFolk(request.getParameter("folk"));//民族
        per.setHometown(request.getParameter("hometown"));//籍贯
        per.setIdcard(request.getParameter("idcard"));//身份证
        per.setHealth(request.getParameter("health"));//健康情况
        per.setMastdegree(request.getParameter("mastdegree"));//最高学历
        per.setCertificate(request.getParameter("certificate"));//其他证书
        per.setEmail(request.getParameter("email"));//电子邮件
        per.setTelephone(request.getParameter("telephone"));//联系电话
        per.setAddress(request.getParameter("address"));//现住址
        per.setMarriage(request.getParameter("marriage"));//婚姻情况
        per.setGenro(request.getParameter("genro"));//政治面貌
        per.setRemark(request.getParameter("remark"));//备注
        per.setPerdrder(request.getParameter("perdrder"));//客户等级
        per.setMobiletelephone(request.getParameter("mobiletelephone"));//手机
        per.setGid(request.getParameter("gid"));//IP段
        per.setPassword(password);//密码
        per.setRelationnumber(new Integer(0));//联系人数量
        String maindid = dao.saveReturn(per);
        String birthday = request.getParameter("birthday").toString();

        //插入人员任职信息表
        HzsysEmpholdpost ep = new HzsysEmpholdpost();
        ep.setPerid(String.valueOf(per.getPersonid()));
        ep.setOrgid(orgid);
        ep.setDepid(dpid);
        ep.setPosid(psid);
        ep.setPtype(Constants.EMP_HOLD_ONE);
        dao.insertinfor(ep);
        
        body = "增加用户成功";
    } catch (Exception ex) {
    	body = "增加用户失败";
        throw new BusinessException("增加用户失败", ex);
    } 
%>
<html>
<head>
    <%@ include file="../inc/action_components.jsp" %>
</head>

<body tt.action.result="true" tt.msg="<%=body %>">
<script>
    function afterSuccess() {
        _parent.__close();
        __invoke(_parent, "onAddEmployeeFinish");
    }
</script>
</body>
</html>